class Solution(object):
    def findWinners(self, matches):
        set0 = set()
        set1 = set()
        set2 = set()
        for u,v in matches:
            if u not in set0 and u not in set1 and u not in set2:
                set0.add(u)
            if v in set0:
                set0.remove(v)
                set1.add(v)
            else:
                if v in set1:
                    set1.remove(v)
                    set2.add(v)
                else:
                    if v not in set2:
                        set1.add(v)
        ans = [list(set0), list(set1)]
        ans[0].sort()
        ans[1].sort()
        return ans